#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //实例化菜单
    fileMenu=new QMenu(this);
    editMenu=new QMenu(this);
    helpMenu=new QMenu(this);
    //填充菜单子接单
    newAct=new QAction(tr("新建"),this);
    newAct->setShortcut(tr("Ctrl+N"));
    newAct->setStatusTip(tr("新建文件"));
    //
    connect(
            newAct,SIGNAL(triggered(bool)),
                this,
                SLOT(newFile())
                );
    //
    cutAct=new QAction(tr("剪切"),this);
    cutAct->setShortcut(tr("Ctrl+X"));
    cutAct->setStatusTip(tr("剪切内容"));
    //
    copyAct=new QAction(tr("复制"),this);
    copyAct->setShortcut(tr("Ctrl+C"));
    copyAct->setStatusTip(tr("复制内容"));
    //
    pasteAct=new QAction(tr("粘贴"),this);
    pasteAct->setShortcut(tr("Ctrl+V"));
    pasteAct->setStatusTip(tr("粘贴内容"));
    //
    aboutQtAct=new QAction(tr("关于Qt"),this);
    aboutQtAct->setStatusTip(tr("关于Qt信息"));
    //
    connect(
                aboutQtAct,
                SIGNAL(triggered(bool)),
                qApp,SLOT(aboutQt())
                );
    //填充菜单
    fileMenu=menuBar()->addMenu(tr("文件"));
    fileMenu->addAction(newAct);
    fileMenu->addSeparator();
    //
    editMenu=menuBar()->addMenu(tr("编辑"));
    editMenu->addAction(cutAct);
    editMenu->addAction(copyAct);
    editMenu->addAction(pasteAct);
    menuBar()->addSeparator();
    //
    helpMenu=menuBar()->addMenu(tr("帮助"));
    helpMenu->addAction(aboutQtAct);
    //工具条
    fileToolBar=addToolBar(tr("新建"));
    fileToolBar->addAction(newAct);
    //
    editToolBar=addToolBar(tr("修改"));
    editToolBar->addAction(cutAct);
    editToolBar->addAction(copyAct);
    editToolBar->addAction(pasteAct);


}
void MainWindow::newFile()
{
    QMessageBox::warning(this,
                         tr("Waring"),
                         tr("创建新文件？"),
                         QMessageBox::Yes|QMessageBox::Default,
                         QMessageBox::No);
}
MainWindow::~MainWindow()
{
    delete ui;
}
